package com.yunsc.admin.controller.store;

import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.system.dto.StoreRoleDTO;
import com.yunsc.system.service.YunscStoreRoleService;
import com.yunsc.system.vo.StoreRoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 商家用户角色记录表
 *
 * @author adan
 * @email 2028038953@gmail.com
 * @date 2023-12-19 20:57:22
 */
@Api(value = "商家用户角色信息接口", tags = "商家信息接口")
@Slf4j
@RestController
@RequestMapping("role")
public class StoreRoleController {

    @Resource
    private YunscStoreRoleService storeRoleService;

    @ApiOperation("查询商家角色信息")
    @GetMapping("/list")
    public Result<?> queryStoreRoleList() {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        List<StoreRoleVO> roleList = storeRoleService.queryStoreRoleList(currentStoreId);
        return Result.resultList(roleList);
    }

    @ApiOperation("编辑商家角色信息")
    @PostMapping("/edit")
    public Result<?> editStoreRole(@RequestBody StoreRoleDTO storeRoleDTO) {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        storeRoleService.editStoreRole(currentStoreId, storeRoleDTO);
        return Result.ok();
    }


    @ApiOperation("删除商家角色信息")
    @PostMapping("/delete")
    public Result<?> deleteStoreRole(@RequestBody StoreRoleDTO storeRoleDTO) {
        storeRoleService.deleteStoreRole(storeRoleDTO.getRoleId());
        return Result.ok();
    }

    @ApiOperation("新增商家角色信息")
    @PostMapping("/add")
    public Result<?> addStoreRole(@RequestBody StoreRoleDTO storeRoleDTO) {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        storeRoleService.addStoreRole(currentStoreId, storeRoleDTO);
        return Result.ok();
    }


}
